//
//  MarketService.m
//  BTCoin
//
//  Created by Robin on 08/03/2018.
//  Copyright © 2018 Robin. All rights reserved.
//

#import "MarketService.h"

@implementation MarketService

DEFINE_SINGLETON_FOR_CLASS(MarketService)

/**获取深度数据*/
- (void)requestDepth:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/appApi.html?action=depth&symbol=1",BaseHttpUrl];
    
    [BaseService post:urlStr dictionay:nil timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

/**获取K线数据*/
- (void)requestKline:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
}

/**获取实时行情*/
- (void)requestMarket:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
}

/**获取最新成交数据*/
- (void)requestTrades:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
}

/**获取分时数据*/
- (void)requestChartData:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/api/v1/klines?%@",HistoryKLineHttpUrl,para];
    
    [BaseService get:urlStr dictionay:nil timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

/**获取行情列表数据*/
- (void)requestPostMarketHomeList:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/trade/market.do?%@",BaseHttpUrl,para];
    NSLog(@"urlPath -- %@",urlStr);
    [BaseService post:urlStr dictionay:nil timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}
@end
